package net.cl.utils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import net.cl.db.CachedResultSet;
import net.cl.db.core.CachedResultSetImpl;

/**
 * 
 * @author caol64@gmail.com
 */
public class JdbcUtil {

	public static void closeQuietly(ResultSet rs) {
		try {
			if (rs != null)
				rs.close();
		} catch (SQLException e) {
		}
	}

	public static void closeQuietly(Statement st) {
		try {
			if (st != null)
				st.close();
		} catch (SQLException e) {
		}
	}

	public static void closeQuietly(Connection conn) {
		try {
			if (conn != null)
				conn.close();
		} catch (SQLException e) {
		}
	}

	/**
	 * 持久化ResultSet，返回CachedResultSet对象，调用完该方法后即可将ResultSet关闭
	 */
	public static CachedResultSet persistence(ResultSet rs) {
		CachedResultSet crs = new CachedResultSetImpl(rs);
		return crs;
	}

}
